/*
 * @lc app=leetcode.cn id=7 lang=typescript
 *
 * [7] 整数反转
 */

// @lc code=start
function reverse(x: number): number {
    const num = x.toString().split("");
    let result = 0;
    if (num[0] === "-") {
        result = -parseInt(num.slice(1).reverse().join(""), 10);
    } else {
        result = parseInt(num.reverse().join(""), 10);
    }
    if (result >= -(2 ** 31) && result <= 2 ** 31 - 1) {
        return result;
    } else {
        return 0;
    }
}

// @lc code=end
